<template>
  <div class="action-button">
    <div
      @click="handleClick"
      :class="`action-button-box ${show ? 'action-button-box-active' : ''}`"
    ></div>
    <transition name="show-menu">
      <div
        @click="toHome"
        v-show="show"
        class="action-button-item to-home-button"
      >
        <div>首页</div>
      </div>
    </transition>
    <transition name="show-menu">
      <div
        @click="toBlog"
        v-show="show"
        class="action-button-item blog-button"
      >
        <div>博客</div>
      </div>
    </transition>
    <transition name="show-menu">
      <div
        @click="showCode"
        v-show="show"
        class="action-button-item show-code-button"
      >
        <div>源码</div>
      </div>
    </transition>
  </div>
  <vue-code-drawer v-model:value="visible"/>
</template>

<script lang="ts" setup>
import {ref, watch} from 'vue'
import VueCodeDrawer from "@/components/VueCodeDrawer.vue"
import {useRoute, useRouter} from "vue-router";

const router = useRouter()
const route = useRoute()
const visible = ref(false)
const show = ref(false)

watch(route, function () {
  show.value = false
})

function handleClick() {
  show.value = !show.value
}

function toHome() {
  router.push('/')
}

function showCode() {
  visible.value = !visible.value
}

function toBlog() {
  window.open('https://cai12317.gitee.io/blog/')
}
</script>

<style scoped lang="scss">
@import "../style/theme";

.action-button {
  position: absolute;
  left: 0;
  top: 0;
  --menu-line-color: #FFF;
  color: var(--menu-line-color);
  user-select: none;

  &-box {
    position: relative;
    left: 20px;
    top: 20px;
    background-color: $default-theme-color;
    width: 100px;
    height: 100px;
    border-radius: 50px;
    cursor: pointer;
    z-index: 999;

    &:before,
    &:after {
      content: '';
      display: inline-block;
      position: absolute;
      width: 60px;
      height: 10px;
      background-color: var(--menu-line-color);
      border-radius: 5px;
      left: 20px;
      transition: all .5s;
    }

    &:before {
      top: 20px;
    }

    &:after {
      top: 45px;
      box-shadow: 0 25px 0 0 var(--menu-line-color);
    }
  }

  &-box-active {

    &::before {
      top: 45px;
      transform: rotate(-45deg);
    }

    &::after {
      top: 45px;
      transform: rotate(45deg);
      box-shadow: 0 0 0 0 transparent;
    }
  }

  &-item {
    position: absolute;
    width: 50px;
    height: 50px;
    background-color: $default-theme-color;
    border-radius: 50%;
    text-align: center;
    line-height: 50px;
    font-weight: bolder;
    transition: all .5s;
    z-index: 1;
    cursor: pointer;
    left: 45px;
    top: 45px;
  }
}

.to-home-button {
  transform: rotate(-25deg) translate(90px, 0);

  div {
    transform: rotate(25deg);
  }
}

.show-code-button {
  transform: rotate(55deg) translate(90px, 0);

  div {
    transform: rotate(-55deg);
  }
}

.blog-button {
  transform: rotate(15deg) translate(90px, 0);

  div {
    transform: rotate(-15deg);
  }
}

.show-menu-enter-from,
.show-menu-leave-to {
  transform: translate(0, 0);
  opacity: 0;
}
</style>
